package com.imonsoft.sqm.service.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.imonsoft.common.constant.ConstantDict;
import com.imonsoft.common.util.MailUtils;
import com.imonsoft.sqm.pojo.sys.User;
import com.imonsoft.sqm.service.basedata.DictionaryService;

@Service("mailSercice")
public class MailSerciceImpl implements MailSercice{
	@Autowired
	private DictionaryService dictionaryService;
	/**
	 * 发送邮件
	 * 
	 * @author yangkui
	 * @param fromEmail
	 *            发件人邮箱
	 * @param List
	 *            <TsUserInfo> toUser 收件人
	 * @param List
	 *            <TsUserInfo> copyUser 抄送人
	 * @param List
	 *            <TsUserInfo> encryUser 密送人
	 * @param title
	 *            邮件标题
	 * @param context
	 *            邮件内容
	 * 
	 * @throws Exception
	 */
	@Override
	public void txSendMail(User toUser, String title, String context) throws Exception {
		//************************四个参数为系统默认邮箱参数，如需修改请到数据字典维护***************************
		// 邮箱服务器名称
		String servicename = dictionaryService.getNameByCodeType(ConstantDict.YXFWQMC, ConstantDict.MAIL);
		// 发送人邮箱名称
		String userEmail = dictionaryService.getNameByCodeType(ConstantDict.FSRYXMC, ConstantDict.MAIL);
		// 邮箱发送密码
		String password = dictionaryService.getNameByCodeType(ConstantDict.FSRYXMM, ConstantDict.MAIL);
		// 邮箱发送人名称
		String username = dictionaryService.getNameByCodeType(ConstantDict.YXFSRMC, ConstantDict.MAIL);
		MailUtils sendMail = new MailUtils(username, toUser.getMail(), toUser.getName(),
				context,1,servicename,userEmail,password);
		sendMail.start();
	}
}
